package cn.tedu.charging.user.service.impl;

import cn.tedu.charging.user.dao.mapper.UserVehicleMapper;
import cn.tedu.charging.user.pojo.po.UserVehicleInfoPO;
import cn.tedu.common.pojo.vo.UserInfoVO;
import cn.tedu.charging.user.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserVehicleMapper userVehicleMapper;
    @Override
    public UserInfoVO getUserInfo(Integer userId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        //where user_Id = userId
        queryWrapper.eq("user_id",userId);
        //select xxx from where user_Id = userId
        //One record is expected, but the query result is multiple records
        // selectOne 查询1个结果 ， 条件是 user_id = 17 查询出两条数据
        UserVehicleInfoPO userVehicleInfo = userVehicleMapper.selectOne(queryWrapper);
        if (userVehicleInfo != null) {
            UserInfoVO userInfoVO = new UserInfoVO();
            userInfoVO.setCarId(userVehicleInfo.getVehicleId());
            return userInfoVO;
        }
        return null;
    }
}
